const Koa = require('koa')
const jwt = require('jsonwebtoken')
const { koaBody } = require("koa-body")

const cors = require('koa2-cors')

const logger = require('koa-logger')
const koaStatic = require('koa-static')

const koaJwt = require('koa-jwt')

const db = require('../json-server/db')

const app = new Koa();

db.init()

app.use(cors())

app.use(koaJwt({
    secret: "2302B",
}).unless({
    path: [/^\/user\/login/, /^\/user\/register/],
})
)

app.use(logger())
app.use(koaStatic(__dirname + "public"))

app.use(koaBody())


const Router = require('@koa/router');

const router = new Router();
const user = require('./routes/user')
const goods = require('./routes/goods')



app.use(router.routes()).use(router.allowedMethods())
app.use(user.routes()).use(user.allowedMethods())
app.use(goods.routes()).use(goods.allowedMethods())

app.listen(8000)